#include "instructions/reserved/invokenative.h"
#include "rtda/heap/class.h"

namespace jvm {
	namespace instructions {

		void INVOKE_NATIVE::execute(std::shared_ptr<rtda::Frame> p_frame)
		{
			auto&& pmethod = p_frame->getMethod();
			auto&& classname = pmethod->getClass()->getName();
			auto&& method_name = pmethod->getName();
			auto&& method_desc = pmethod->getDescriptor();

			auto&& native_method_func = native::Registry::findNativeMethod(classname, method_name, method_desc);
			if (!native_method_func)
			{
				auto&& method_info = classname + "." + method_name + method_desc;
				LOG_ERROR("java.lang.UnsatisfiedLinkError: " << method_info);
				throw std::runtime_error("java.lang.UnsatisfiedLinkError: " + method_info);
			}

			native_method_func(p_frame);
		}

	} // namespace instructions
} // namespace jvm
